﻿using System.Collections.Generic;
using System.Linq;

namespace GameName1
{
    class GameObjectsManager
    {
        private static GameObjectsManager _instance;

        private List<GameObject> _gameObjects = new List<GameObject>();

        private GameObjectsManager()
        { }

        public static GameObjectsManager GetInstance()
        {
            if(_instance == null) _instance = new GameObjectsManager();

            return _instance;
        }

        public void Instantiate(GameObject gameObject)
        {
           _gameObjects.Add(gameObject); 
        }

        public void DestroyAll()
        {
            _gameObjects.Clear();
        }
        public void DestroyAllObjectsOfType<T>()
        {
            _gameObjects.RemoveAll(w => w is T);
        }      
        public void Destroy(GameObject gameObject)
        {
            _gameObjects.Remove(gameObject);
        }

        public List<T> GetAllObjectsOfType<T>()
        {
            return _gameObjects.FindAll(w => w is T).Cast<T>().ToList();
        }
    }
}
